home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / pbm / Part2 < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  37.7 KB

  1. From: jef@webster.UUCP (Jef Poskanzer)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i081: pbm - Portable Bitmap programs, Part 2/4
  4. Message-ID: <8803292002.AA24561@webster.sybase.uucp>
  5. Date: 29 Mar 88 20:02:52 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 81
  9. Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>
  10. Archive-Name: pbm/Part2
  11.  
  12. #! /bin/sh
  13. # This is a shell archive, meaning:
  14. # 1. Remove everything above the #! /bin/sh line.
  15. # 2. Save the resulting text in a file.
  16. # 3. Execute the file with /bin/sh (not csh) to create the files:
  17. #    xbmtopbm.c
  18. #    xbmtopbm.man
  19. #    xwdtopbm.c
  20. #    xwdtopbm.man
  21. #    pbmtocbm.c
  22. #    pbmtocbm.man
  23. #    pbmtoicon.c
  24. #    pbmtoicon.man
  25. #    pbmtops.c
  26. #    pbmtops.man
  27. #    pbmtoptx.c
  28. #    pbmtoptx.man
  29. #    pbmtorast.c
  30. #    pbmtorast.man
  31. # This archive created: Mon Mar 28 12:12:08 1988
  32. # By:    Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
  33. export PATH; PATH=/bin:$PATH
  34. echo shar: extracting "'xbmtopbm.c'" '(4125 characters)'
  35. if test -f 'xbmtopbm.c'
  36. then
  37.     echo shar: will not over-write existing file "'xbmtopbm.c'"
  38. else
  39. sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.c'
  40. X/* xbmtopbm.c - read an X bitmap file and produce a portable bitmap
  41. X**
  42. X** Copyright (C) 1988 by Jef Poskanzer.
  43. X**
  44. X** Permission to use, copy, modify, and distribute this software and its
  45. X** documentation for any purpose and without fee is hereby granted, provided
  46. X** that the above copyright notice appear in all copies and that both that
  47. X** copyright notice and this permission notice appear in supporting
  48. X** documentation.  This software is provided "as is" without express or
  49. X** implied warranty.
  50. X*/
  51. X
  52. X#include <stdio.h>
  53. X#include <sys/types.h>
  54. X#include "pbm.h"
  55. X
  56. Xmain( argc, argv )
  57. Xint argc;
  58. Xchar *argv[];
  59. X    {
  60. X    FILE *ifd;
  61. X    bit **bits;
  62. X    int rows, cols, row, col, charcount;
  63. X    char *data, mask;
  64. X
  65. X    if ( argc > 2 )
  66. X    {
  67. X    fprintf( stderr, "usage: %s [bitmapfile]\n", argv[0] );
  68. X    exit( 1 );
  69. X    }
  70. X    
  71. X    if ( argc == 2 )
  72. X    {
  73. X    ifd = fopen( argv[1], "r" );
  74. X    if ( ifd == NULL )
  75. X        {
  76. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  77. X        exit( 1 );
  78. X        }
  79. X    }
  80. X    else
  81. X    ifd = stdin;
  82. X
  83. X    if ( ReadBitmapFile( ifd, &cols, &rows, &data ) < 0 )
  84. X    {
  85. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  86. X    exit( 1 );
  87. X    }
  88. X
  89. X    if ( ifd != stdin )
  90. X    fclose( ifd );
  91. X
  92. X    bits = pbm_allocarray( cols, rows );
  93. X
  94. X    for ( row = 0; row < rows; row++ )
  95. X    {
  96. X    charcount = 0;
  97. X    mask = 1;
  98. X    for ( col = 0; col < cols; col++ )
  99. X        {
  100. X        if ( charcount >= 8 )
  101. X        {
  102. X        data++;
  103. X        charcount = 0;
  104. X        mask = 1;
  105. X        }
  106. X        bits[row][col] = ( *data & mask ) ? 1 : 0;
  107. X        charcount++;
  108. X        mask = mask << 1;
  109. X        }
  110. X    data++;
  111. X    }
  112. X
  113. X    pbm_writepbm( stdout, bits, cols, rows );
  114. X
  115. X    exit( 0 );
  116. X    }
  117. X
  118. X
  119. X#ifdef    OS_SYSV
  120. X#include <string.h>
  121. X#else    OS_SYSV
  122. X#include <strings.h>
  123. X#endif    OS_SYSV
  124. X
  125. X#define MAX_LINE 81
  126. X
  127. Xint
  128. XReadBitmapFile( stream, widthP, heightP, dataP )
  129. XFILE *stream;
  130. Xint *widthP, *heightP;
  131. Xchar **dataP;
  132. X    {
  133. X    char line[MAX_LINE], name_and_type[MAX_LINE];
  134. X    char *ptr, *t;
  135. X    int bytes, bytes_per_line, value, version10p, raster_length, padding;
  136. X
  137. X    *widthP = *heightP = -1;
  138. X
  139. X    for ( ; ; )
  140. X    {
  141. X    if ( ! fgets( line, MAX_LINE, stream ) )
  142. X        break;
  143. X    if ( strlen( line ) == MAX_LINE - 1 )
  144. X        {
  145. X        fprintf( stderr, "Line too long.\n" );
  146. X        return ( -1 );
  147. X        }
  148. X
  149. X    if (sscanf(line, "#define %s %d", name_and_type, &value) == 2)
  150. X        {
  151. X#ifdef    OS_SYSV
  152. X        if ( ! (t = strrchr( name_and_type, '_' )) )
  153. X#else    OS_SYSV
  154. X        if ( ! (t = rindex( name_and_type, '_' )) )
  155. X#endif    OS_SYSV
  156. X        t = name_and_type;
  157. X        else
  158. X        t++;
  159. X        if ( ! strcmp( "width", t ) )
  160. X        *widthP = value;
  161. X        if ( ! strcmp( "height", t ) )
  162. X        *heightP = value;
  163. X        continue;
  164. X        }
  165. X    
  166. X    if ( sscanf( line, "static short %s = {", name_and_type ) == 1 )
  167. X        {
  168. X        version10p = 1;
  169. X        break;
  170. X        }
  171. X    else if ( sscanf( line, "static char %s = {", name_and_type ) == 1 )
  172. X        {
  173. X        version10p = 0;
  174. X        break;
  175. X        }
  176. X    else
  177. X        continue;
  178. X    }
  179. X#ifdef    OS_SYSV
  180. X    if ( ! (t = strrchr( name_and_type, '_' )) )
  181. X#else    OS_SYSV
  182. X    if ( ! (t = rindex( name_and_type, '_' )) )
  183. X#endif    OS_SYSV
  184. X    t = name_and_type;
  185. X    else
  186. X    t++;
  187. X    
  188. X    if ( *widthP == -1 )
  189. X    {
  190. X    fprintf( stderr, "Invalid width.\n" );
  191. X    return ( -1 );
  192. X    }
  193. X    if ( *heightP == -1 )
  194. X    {
  195. X    fprintf( stderr, "Invalid height.\n" );
  196. X    return ( -1 );
  197. X    }
  198. X
  199. X    padding = 0;
  200. X    if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10p )
  201. X    padding = 1;
  202. X
  203. X    bytes_per_line = (*widthP+7)/8 + padding;
  204. X    
  205. X    raster_length =  bytes_per_line * *heightP;
  206. X    *dataP = (char *) malloc( raster_length );
  207. X    if ( ! *dataP )
  208. X    {
  209. X    fprintf( stderr, "Not enough memory.\n" );
  210. X    return ( -1 );
  211. X    }
  212. X
  213. X    if ( version10p )
  214. X    for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 )
  215. X        {
  216. X        if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
  217. X        {
  218. X        fprintf( stderr, "Error scanning bits item.\n" );
  219. X        return ( -1 );
  220. X        }
  221. X        *(ptr++) = value & 0xff;
  222. X        if ( (! padding) || ((bytes+2) % bytes_per_line) )
  223. X        *(ptr++) = value >> 8;
  224. X        }
  225. X    else
  226. X        for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes++ )
  227. X        {
  228. X        if ( fscanf( stream, " 0x%x%*[,}]%*[ \n]", &value ) != 1 )
  229. X            {
  230. X            fprintf( stderr, "Error scanning bits item.\n" );
  231. X            return ( -1 );
  232. X            }
  233. X        *(ptr++) = value;
  234. X        }
  235. X
  236. X    return ( 0 );
  237. X    }
  238. SHAR_EOF
  239. if test 4125 -ne "`wc -c < 'xbmtopbm.c'`"
  240. then
  241.     echo shar: error transmitting "'xbmtopbm.c'" '(should have been 4125 characters)'
  242. fi
  243. fi # end of overwriting check
  244. echo shar: extracting "'xbmtopbm.man'" '(980 characters)'
  245. if test -f 'xbmtopbm.man'
  246. then
  247.     echo shar: will not over-write existing file "'xbmtopbm.man'"
  248. else
  249. sed 's/^X//' << \SHAR_EOF > 'xbmtopbm.man'
  250. X.TH xbmtopbm 1 "13 February 1988"
  251. X.SH NAME
  252. Xxbmtopbm - convert X11 and X10 bitmaps into portable bitmaps
  253. X.SH SYNOPSIS
  254. Xxbmtopbm [bitmapfile]
  255. X.SH DESCRIPTION
  256. XReads an X11 or X10 bitmap as input.
  257. XProduces a portable bitmap as output.
  258. X.SH "SEE ALSO"
  259. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xwdtopbm(1),
  260. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  261. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  262. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  263. Xpbmpaste(1), pbmenlarge(1)
  264. X.SH AUTHOR
  265. XCopyright (C) 1988 by Jef Poskanzer.
  266. X
  267. XPermission to use, copy, modify, and distribute this software and its
  268. Xdocumentation for any purpose and without fee is hereby granted, provided
  269. Xthat the above copyright notice appear in all copies and that both that
  270. Xcopyright notice and this permission notice appear in supporting
  271. Xdocumentation.  This software is provided "as is" without express or
  272. Ximplied warranty.
  273. SHAR_EOF
  274. if test 980 -ne "`wc -c < 'xbmtopbm.man'`"
  275. then
  276.     echo shar: error transmitting "'xbmtopbm.man'" '(should have been 980 characters)'
  277. fi
  278. fi # end of overwriting check
  279. echo shar: extracting "'xwdtopbm.c'" '(7751 characters)'
  280. if test -f 'xwdtopbm.c'
  281. then
  282.     echo shar: will not over-write existing file "'xwdtopbm.c'"
  283. else
  284. sed 's/^X//' << \SHAR_EOF > 'xwdtopbm.c'
  285. X/* xwdtopbm.c - read an X11 window dump file and write a portable bitmap
  286. X**
  287. X** Copyright (C) 1988 by Jef Poskanzer.
  288. X**
  289. X** Permission to use, copy, modify, and distribute this software and its
  290. X** documentation for any purpose and without fee is hereby granted, provided
  291. X** that the above copyright notice appear in all copies and that both that
  292. X** copyright notice and this permission notice appear in supporting
  293. X** documentation.  This software is provided "as is" without express or
  294. X** implied warranty.
  295. X*/
  296. X
  297. X#include <stdio.h>
  298. X#include "pbm.h"
  299. X
  300. Xmain( argc, argv )
  301. Xint argc;
  302. Xchar *argv[];
  303. X    {
  304. X    FILE *ifd;
  305. X    bit **bits, getbit();
  306. X    int rows, cols, padR, row, col;
  307. X
  308. X    if ( argc > 2 )
  309. X    {
  310. X    fprintf( stderr, "usage:  %s [xwdfile]\n", argv[0] );
  311. X    exit( 1 );
  312. X    }
  313. X
  314. X    if ( argc == 2 )
  315. X    {
  316. X        ifd = fopen( argv[1], "r" );
  317. X        if ( ifd == NULL )
  318. X        {
  319. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  320. X        exit( 1 );
  321. X        }
  322. X    }
  323. X    else
  324. X    ifd = stdin;
  325. X
  326. X    getinit( ifd, &cols, &rows, &padR );
  327. X
  328. X    bits = pbm_allocarray( cols, rows );
  329. X
  330. X    for ( row = 0; row < rows; row++ )
  331. X    {
  332. X        for ( col = 0; col < cols; col++ )
  333. X        bits[row][col] = getbit( ifd );
  334. X        for ( col = 0; col < padR; col++ )
  335. X        (void) getbit( ifd );
  336. X    }
  337. X
  338. X    if ( ifd != stdin )
  339. X    fclose( ifd );
  340. X    
  341. X    pbm_writepbm( stdout, bits, cols, rows );
  342. X
  343. X    exit( 0 );
  344. X    }
  345. X
  346. X
  347. Xunsigned char bitem;
  348. Xshort sitem;
  349. Xint bits_per_item, bits_used, bit_shift, bit_order, bit_invert;
  350. X
  351. X/* The following defs are taken from various X10 header files. */
  352. X#define X10WD_FILE_VERSION 6
  353. Xtypedef struct {
  354. X    int header_size;        /* Size of the entire file header (bytes). */
  355. X    int file_version;        /* X10WD_FILE_VERSION */
  356. X    int display_type;        /* Display type. */
  357. X    int display_planes;        /* Number of display planes. */
  358. X    int pixmap_format;        /* Pixmap format. */
  359. X    int pixmap_width;        /* Pixmap width. */
  360. X    int pixmap_height;        /* Pixmap height. */
  361. X    short window_width;        /* Window width. */
  362. X    short window_height;    /* Window height. */
  363. X    short window_x;        /* Window upper left X coordinate. */
  364. X    short window_y;        /* Window upper left Y coordinate. */
  365. X    short window_bdrwidth;    /* Window border width. */
  366. X    short window_ncolors;    /* number of Color entries in this window */
  367. X    } X10WDFileHeader;
  368. X
  369. Xtypedef struct {
  370. X    int pixel;
  371. X    unsigned short red, green, blue;
  372. X    } X10Color;
  373. X
  374. X
  375. X/* The following defs are taken from various X11 header files. */
  376. Xtypedef unsigned long xwdval;
  377. X#define X11WD_FILE_VERSION 7
  378. Xtypedef struct {
  379. X    xwdval header_size;        /* Size of the entire file header (bytes). */
  380. X    xwdval file_version;    /* X11WD_FILE_VERSION */
  381. X    xwdval pixmap_format;    /* Pixmap format */
  382. X    xwdval pixmap_depth;    /* Pixmap depth */
  383. X    xwdval pixmap_width;    /* Pixmap width */
  384. X    xwdval pixmap_height;    /* Pixmap height */
  385. X    xwdval xoffset;        /* Bitmap x offset */
  386. X    xwdval byte_order;        /* MSBFirst, LSBFirst */
  387. X    xwdval bitmap_unit;        /* Bitmap unit */
  388. X    xwdval bitmap_bit_order;    /* MSBFirst, LSBFirst */
  389. X    xwdval bitmap_pad;        /* Bitmap scanline pad */
  390. X    xwdval bits_per_pixel;    /* Bits per pixel */
  391. X    xwdval bytes_per_line;    /* Bytes per scanline */
  392. X    xwdval visual_class;    /* Class of colormap */
  393. X    xwdval red_mask;        /* Z red mask */
  394. X    xwdval green_mask;        /* Z green mask */
  395. X    xwdval blue_mask;        /* Z blue mask */
  396. X    xwdval bits_per_rgb;    /* Log base 2 of distinct color values */
  397. X    xwdval colormap_entries;    /* Number of entries in colormap */
  398. X    xwdval ncolors;        /* Number of Color structures */
  399. X    xwdval window_width;    /* Window width */
  400. X    xwdval window_height;    /* Window height */
  401. X    long window_x;        /* Window upper left X coordinate */
  402. X    long window_y;        /* Window upper left Y coordinate */
  403. X    xwdval window_bdrwidth;    /* Window border width */
  404. X    } X11WDFileHeader;
  405. X
  406. Xtypedef struct {
  407. X    unsigned long pixel;
  408. X    unsigned short red, green, blue;
  409. X    char flags;            /* do_red, do_green, do_blue */
  410. X    char pad;
  411. X    } X11XColor;
  412. X
  413. X
  414. Xgetinit( file, colP, rowP, padRP )
  415. XFILE *file;
  416. Xint *colP, *rowP, *padRP;
  417. X    {
  418. X    int header_size;
  419. X    int file_version;
  420. X    X10WDFileHeader h10;
  421. X    X11WDFileHeader h11;
  422. X    char junk[10000];
  423. X
  424. X    if ( fread( &header_size, sizeof( header_size ), 1, file ) != 1 )
  425. X    {
  426. X    fprintf( stderr, "Couldn't read XWD header size.\n" );
  427. X    exit( 1 );
  428. X    }
  429. X    if ( fread( &file_version, sizeof( file_version ), 1, file ) != 1 )
  430. X    {
  431. X    fprintf( stderr, "Couldn't read XWD file version.\n" );
  432. X    exit( 1 );
  433. X    }
  434. X    if ( file_version == X10WD_FILE_VERSION )
  435. X    {
  436. X    if ( fread( &h10.display_type, sizeof( h10 ) - 2 * sizeof( int ), 1,
  437. X                    file ) != 1 )
  438. X        {
  439. X        fprintf( stderr, "Couldn't read X10 XWD file header.\n" );
  440. X        exit( 1 );
  441. X        }
  442. X    if ( fread( junk, header_size - sizeof( h10 ), 1, file ) != 1 )
  443. X        {
  444. X        fprintf( stderr, "Couldn't read rest of X10 XWD file header.\n" );
  445. X        exit( 1 );
  446. X        }
  447. X    if ( fread( junk, sizeof(X10Color), h10.window_ncolors, file ) !=
  448. X         h10.window_ncolors )
  449. X        {
  450. X        fprintf( stderr, "Couldn't read X10 XWD colormap.\n" );
  451. X        exit( 1 );
  452. X        }
  453. X
  454. X    /* Check whether we can handle this dump. */
  455. X    if ( h10.window_ncolors != 0 )
  456. X        {
  457. X        fprintf( stderr, "Can't handle X10 window_ncolors != 0.\n" );
  458. X        exit( 1 );
  459. X        }
  460. X    if ( h10.pixmap_format != 0 )
  461. X        {
  462. X        fprintf( stderr, "Can't handle X10 pixmap_format %d.\n",
  463. X             h10.pixmap_format );
  464. X        exit( 1 );
  465. X        }
  466. X
  467. X    *colP = h10.pixmap_width;
  468. X    *rowP = h10.pixmap_height;
  469. X    *padRP = ( h10.pixmap_width + 15 ) / 16 * 16 - h10.pixmap_width;
  470. X    bits_per_item = 16;
  471. X    bit_order = 0;
  472. X    bit_invert = 1;
  473. X    bits_used = 16;
  474. X    }
  475. X    else if ( file_version == X11WD_FILE_VERSION )
  476. X    {
  477. X    if ( fread( &h11.pixmap_format, sizeof( h11 ) - 2 * sizeof( xwdval ),
  478. X            1, file ) != 1 )
  479. X        {
  480. X        fprintf( stderr, "Couldn't read X11 XWD file header.\n" );
  481. X        exit( 1 );
  482. X        }
  483. X    if ( fread( junk, header_size - sizeof( h11 ), 1, file ) != 1 )
  484. X        {
  485. X        fprintf( stderr, "Couldn't read rest of X11 XWD file header.\n" );
  486. X        exit( 1 );
  487. X        }
  488. X    if ( fread( junk, sizeof( X11XColor ), h11.ncolors, file ) !=
  489. X         h11.ncolors )
  490. X        {
  491. X        fprintf( stderr, "Couldn't read X11 XWD colormap.\n" );
  492. X        exit( 1 );
  493. X        }
  494. X
  495. X    /* Check whether we can handle this dump. */
  496. X    if ( h11.pixmap_depth != 1 )
  497. X        {
  498. X        fprintf( stderr, "Can't handle X11 pixmap_depth > 1.\n" );
  499. X        exit( 1 );
  500. X        }
  501. X    if ( h11.colormap_entries != 2 )
  502. X        {
  503. X        fprintf( stderr, "Can't handle X11 colormap_entries != 2.\n" );
  504. X        exit( 1 );
  505. X        }
  506. X    if ( h11.ncolors != 2 )
  507. X        {
  508. X        fprintf( stderr, "Can't handle X11 ncolors != 2.\n" );
  509. X        exit( 1 );
  510. X        }
  511. X    if ( h11.pixmap_format != 2 )
  512. X        {
  513. X        fprintf( stderr, "Can't handle X11 pixmap_format %d.\n",
  514. X             h11.pixmap_format );
  515. X        exit( 1 );
  516. X        }
  517. X
  518. X    *colP = h11.pixmap_width;
  519. X    *rowP = h11.pixmap_height;
  520. X    *padRP = h11.bytes_per_line * 8 - h11.pixmap_width;
  521. X    bits_per_item = 8;
  522. X    bit_order = h11.bitmap_bit_order;
  523. X    bit_invert = 0;
  524. X    bits_used = 8;
  525. X    }
  526. X    else
  527. X    {
  528. X    fprintf( stderr, "Unknown XWD file version: %d.\n", file_version );
  529. X    exit( 1 );
  530. X    }
  531. X    }
  532. X
  533. Xbit
  534. Xgetbit( file )
  535. XFILE *file;
  536. X    {
  537. X    bit b;
  538. X
  539. X    if ( bits_used == bits_per_item )
  540. X    {
  541. X    if ( bits_per_item == 16 )
  542. X        {
  543. X        if ( fread( &sitem, 2, 1, file ) != 1 )
  544. X        {
  545. X        fprintf( stderr, "Couldn't read short bits.\n" );
  546. X        exit( 1 );
  547. X        }
  548. X        }
  549. X    else
  550. X        {
  551. X        if ( fread( &bitem, 1, 1, file ) != 1 )
  552. X        {
  553. X        fprintf( stderr, "Couldn't read byte bits.\n" );
  554. X        exit( 1 );
  555. X        }
  556. X        }
  557. X    bits_used = 0;
  558. X
  559. X    if ( bit_order == 1 )
  560. X        bit_shift = bits_per_item - 1;
  561. X    else
  562. X        bit_shift = 0;
  563. X    }
  564. X
  565. X    bits_used++;
  566. X    if ( bits_per_item == 16 )
  567. X    b = ( sitem >> bit_shift) & 1;
  568. X    else
  569. X    b = ( bitem >> bit_shift) & 1;
  570. X    if ( bit_invert )
  571. X    b = 1 - b;
  572. X
  573. X    if ( bit_order == 1 )
  574. X    bit_shift--;
  575. X    else
  576. X    bit_shift++;
  577. X
  578. X    return ( b );
  579. X    }
  580. SHAR_EOF
  581. if test 7751 -ne "`wc -c < 'xwdtopbm.c'`"
  582. then
  583.     echo shar: error transmitting "'xwdtopbm.c'" '(should have been 7751 characters)'
  584. fi
  585. fi # end of overwriting check
  586. echo shar: extracting "'xwdtopbm.man'" '(1465 characters)'
  587. if test -f 'xwdtopbm.man'
  588. then
  589.     echo shar: will not over-write existing file "'xwdtopbm.man'"
  590. else
  591. sed 's/^X//' << \SHAR_EOF > 'xwdtopbm.man'
  592. X.TH xwdtopbm 1 "21 March 1988"
  593. X.SH NAME
  594. Xxwdtopbm - convert X11 and X10 window dump files into portable bitmaps
  595. X.SH SYNOPSIS
  596. Xxwdtopbm [xwdfile]
  597. X.SH DESCRIPTION
  598. XReads an X11 or X10 window dump file as input.
  599. XProduces a portable bitmap as output.
  600. X.LP
  601. XUsing this program, you can convert anything on an X workstation's screen
  602. Xinto a pbm bitmap.
  603. XJust display whatever you're interested in, do an xwd, run it through
  604. Xxwdtopbm, and then use pbmcut to select the part you want.
  605. X.LP
  606. XNote that this tool only works for monochrome dump files.
  607. XAlso note that there is currently no pbmtoxwd tool.
  608. X.SH BUGS
  609. XI haven't tested this tool with very many configurations, so there are
  610. Xprobably bugs.
  611. XPlease let me know if you find any.
  612. X.SH "SEE ALSO"
  613. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1),
  614. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  615. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  616. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  617. Xpbmpaste(1), pbmenlarge(1)
  618. X.SH AUTHOR
  619. XCopyright (C) 1988 by Jef Poskanzer.
  620. X
  621. XPermission to use, copy, modify, and distribute this software and its
  622. Xdocumentation for any purpose and without fee is hereby granted, provided
  623. Xthat the above copyright notice appear in all copies and that both that
  624. Xcopyright notice and this permission notice appear in supporting
  625. Xdocumentation.  This software is provided "as is" without express or
  626. Ximplied warranty.
  627. SHAR_EOF
  628. if test 1465 -ne "`wc -c < 'xwdtopbm.man'`"
  629. then
  630.     echo shar: error transmitting "'xwdtopbm.man'" '(should have been 1465 characters)'
  631. fi
  632. fi # end of overwriting check
  633. echo shar: extracting "'pbmtocbm.c'" '(1856 characters)'
  634. if test -f 'pbmtocbm.c'
  635. then
  636.     echo shar: will not over-write existing file "'pbmtocbm.c'"
  637. else
  638. sed 's/^X//' << \SHAR_EOF > 'pbmtocbm.c'
  639. X/* pbmtocbm.c - read a portable bitmap and produce a compact bitmap
  640. X**
  641. X** Copyright (C) 1988 by Jef Poskanzer.
  642. X**
  643. X** Permission to use, copy, modify, and distribute this software and its
  644. X** documentation for any purpose and without fee is hereby granted, provided
  645. X** that the above copyright notice appear in all copies and that both that
  646. X** copyright notice and this permission notice appear in supporting
  647. X** documentation.  This software is provided "as is" without express or
  648. X** implied warranty.
  649. X*/
  650. X
  651. X#include <stdio.h>
  652. X#include "pbm.h"
  653. X
  654. Xmain( argc, argv )
  655. Xint argc;
  656. Xchar *argv[];
  657. X    {
  658. X    FILE *ifd;
  659. X    bit **bits;
  660. X    int rows, cols, row, col;
  661. X
  662. X    if ( argc > 2 )
  663. X    {
  664. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  665. X    exit( 1 );
  666. X    }
  667. X
  668. X    if ( argc == 2 )
  669. X    {
  670. X        ifd = fopen( argv[1], "r" );
  671. X        if ( ifd == NULL )
  672. X        {
  673. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  674. X        exit( 1 );
  675. X        }
  676. X    }
  677. X    else
  678. X    ifd = stdin;
  679. X
  680. X    bits = pbm_readpbm( ifd, &cols, &rows );
  681. X
  682. X    if ( ifd != stdin )
  683. X    fclose( ifd );
  684. X    
  685. X    putchar( (char) 42 );
  686. X    putchar( (char) 23 );
  687. X    putchar( (char) ( ( cols >> 8 ) & 0xff ) );
  688. X    putchar( (char) ( cols & 0xff ) );
  689. X    putchar( (char) ( ( rows >> 8 ) & 0xff ) );
  690. X    putchar( (char) ( rows & 0xff ) );
  691. X
  692. X    putinit( );
  693. X    for ( row = 0; row < rows; row++ )
  694. X        for ( col = 0; col < cols; col++ )
  695. X        putbit( bits[row][col] );
  696. X    putrest( );
  697. X
  698. X    exit( 0 );
  699. X    }
  700. X
  701. X
  702. Xint item, bitsperitem, bitshift;
  703. X
  704. Xputinit( )
  705. X    {
  706. X    bitsperitem = 0;
  707. X    item = 0;
  708. X    bitshift = 7;
  709. X    }
  710. X
  711. Xputbit( b )
  712. Xbit b;
  713. X    {
  714. X    if ( bitsperitem == 8 )
  715. X    putitem( );
  716. X    bitsperitem++;
  717. X    if ( b )
  718. X    item += 1 << bitshift;
  719. X    bitshift--;
  720. X    }
  721. X
  722. Xputrest( )
  723. X    {
  724. X    if ( bitsperitem > 0 )
  725. X    putitem( );
  726. X    }
  727. X
  728. Xputitem( )
  729. X    {
  730. X    putchar( (char) item );
  731. X    bitsperitem = 0;
  732. X    item = 0;
  733. X    bitshift = 7;
  734. X    }
  735. SHAR_EOF
  736. if test 1856 -ne "`wc -c < 'pbmtocbm.c'`"
  737. then
  738.     echo shar: error transmitting "'pbmtocbm.c'" '(should have been 1856 characters)'
  739. fi
  740. fi # end of overwriting check
  741. echo shar: extracting "'pbmtocbm.man'" '(969 characters)'
  742. if test -f 'pbmtocbm.man'
  743. then
  744.     echo shar: will not over-write existing file "'pbmtocbm.man'"
  745. else
  746. sed 's/^X//' << \SHAR_EOF > 'pbmtocbm.man'
  747. X.TH pbmtocbm 1 "13 February 1988"
  748. X.SH NAME
  749. Xpbmtocbm - convert portable bitmaps into compact bitmaps
  750. X.SH SYNOPSIS
  751. Xpbmtocbm [pbmfile]
  752. X.SH DESCRIPTION
  753. XReads a portable bitmap as input.
  754. XProduces a compact bitmap as output.
  755. X.SH "SEE ALSO"
  756. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  757. Xpbmtoicon(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  758. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  759. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  760. Xpbmpaste(1), pbmenlarge(1)
  761. X.SH AUTHOR
  762. XCopyright (C) 1988 by Jef Poskanzer.
  763. X
  764. XPermission to use, copy, modify, and distribute this software and its
  765. Xdocumentation for any purpose and without fee is hereby granted, provided
  766. Xthat the above copyright notice appear in all copies and that both that
  767. Xcopyright notice and this permission notice appear in supporting
  768. Xdocumentation.  This software is provided "as is" without express or
  769. Ximplied warranty.
  770. SHAR_EOF
  771. if test 969 -ne "`wc -c < 'pbmtocbm.man'`"
  772. then
  773.     echo shar: error transmitting "'pbmtocbm.man'" '(should have been 969 characters)'
  774. fi
  775. fi # end of overwriting check
  776. echo shar: extracting "'pbmtoicon.c'" '(2414 characters)'
  777. if test -f 'pbmtoicon.c'
  778. then
  779.     echo shar: will not over-write existing file "'pbmtoicon.c'"
  780. else
  781. sed 's/^X//' << \SHAR_EOF > 'pbmtoicon.c'
  782. X/* pbmtoicon.c - read a portable bitmap and produce a Sun icon file
  783. X**
  784. X** Copyright (C) 1988 by Jef Poskanzer.
  785. X**
  786. X** Permission to use, copy, modify, and distribute this software and its
  787. X** documentation for any purpose and without fee is hereby granted, provided
  788. X** that the above copyright notice appear in all copies and that both that
  789. X** copyright notice and this permission notice appear in supporting
  790. X** documentation.  This software is provided "as is" without express or
  791. X** implied warranty.
  792. X*/
  793. X
  794. X#include <stdio.h>
  795. X#include "pbm.h"
  796. X
  797. Xmain( argc, argv )
  798. Xint argc;
  799. Xchar *argv[];
  800. X    {
  801. X    FILE *ifd;
  802. X    bit **bits;
  803. X    int rows, cols, rucols, padleft, padright, row, col;
  804. X    char ch;
  805. X
  806. X    if ( argc > 2 )
  807. X    {
  808. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  809. X    exit( 1 );
  810. X    }
  811. X
  812. X    if ( argc == 2 )
  813. X    {
  814. X        ifd = fopen( argv[1], "r" );
  815. X        if ( ifd == NULL )
  816. X        {
  817. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  818. X        exit( 1 );
  819. X        }
  820. X    }
  821. X    else
  822. X    ifd = stdin;
  823. X
  824. X    bits = pbm_readpbm( ifd, &cols, &rows );
  825. X
  826. X    if ( ifd != stdin )
  827. X    fclose( ifd );
  828. X    
  829. X    /* Round cols up to the nearest multiple of 16. */
  830. X    rucols = ( cols + 15 ) / 16;
  831. X    rucols = rucols * 16;
  832. X    padleft = ( rucols - cols ) / 2;
  833. X    padright = rucols - cols - padleft;
  834. X
  835. X    printf( "/* Format_version=1, Width=%d, Height=%d", rucols, rows );
  836. X    printf( ", Depth=1, Valid_bits_per_item=16\n */\n" );
  837. X
  838. X    putinit( );
  839. X    for ( row = 0; row < rows; row++ )
  840. X    {
  841. X    for ( col = 0; col < padleft; col++ )
  842. X        putbit( 0 );
  843. X        for ( col = 0; col < cols; col++ )
  844. X        putbit( bits[row][col] );
  845. X    for ( col = 0; col < padright; col++ )
  846. X        putbit( 0 );
  847. X        }
  848. X    putrest( );
  849. X
  850. X    exit( 0 );
  851. X    }
  852. X
  853. X
  854. Xint item, bitsperitem, bitshift, itemsperline, firstitem;
  855. X
  856. Xputinit( )
  857. X    {
  858. X    itemsperline = 0;
  859. X    bitsperitem = 0;
  860. X    item = 0;
  861. X    bitshift = 15;
  862. X    firstitem = 1;
  863. X    }
  864. X
  865. Xputbit( b )
  866. Xbit b;
  867. X    {
  868. X    if ( bitsperitem == 16 )
  869. X    putitem( );
  870. X    bitsperitem++;
  871. X    if ( b )
  872. X    item += 1 << bitshift;
  873. X    bitshift--;
  874. X    }
  875. X
  876. Xputrest( )
  877. X    {
  878. X    if ( bitsperitem > 0 )
  879. X    putitem( );
  880. X    putchar( '\n' );
  881. X    }
  882. X
  883. Xputitem( )
  884. X    {
  885. X    if ( firstitem )
  886. X    firstitem = 0;
  887. X    else
  888. X    putchar( ',' );
  889. X    if ( itemsperline == 8 )
  890. X    {
  891. X    putchar( '\n' );
  892. X    itemsperline = 0;
  893. X    }
  894. X    if ( itemsperline == 0 )
  895. X    putchar( '\t' );
  896. X    itemsperline++;
  897. X    printf( "0x%04x", item );
  898. X    bitsperitem = 0;
  899. X    item = 0;
  900. X    bitshift = 15;
  901. X    }
  902. SHAR_EOF
  903. if test 2414 -ne "`wc -c < 'pbmtoicon.c'`"
  904. then
  905.     echo shar: error transmitting "'pbmtoicon.c'" '(should have been 2414 characters)'
  906. fi
  907. fi # end of overwriting check
  908. echo shar: extracting "'pbmtoicon.man'" '(960 characters)'
  909. if test -f 'pbmtoicon.man'
  910. then
  911.     echo shar: will not over-write existing file "'pbmtoicon.man'"
  912. else
  913. sed 's/^X//' << \SHAR_EOF > 'pbmtoicon.man'
  914. X.TH pbmtoicon 1 "13 February 1988"
  915. X.SH NAME
  916. Xpbmtoicon - convert portable bitmaps into Sun icons 
  917. X.SH SYNOPSIS
  918. Xpbmtoicon [pbmfile]
  919. X.SH DESCRIPTION
  920. XReads a portable bitmap as input.
  921. XProduces a Sun icon as output.
  922. X.SH "SEE ALSO"
  923. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  924. Xpbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  925. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  926. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  927. Xpbmpaste(1), pbmenlarge(1)
  928. X.SH AUTHOR
  929. XCopyright (C) 1988 by Jef Poskanzer.
  930. X
  931. XPermission to use, copy, modify, and distribute this software and its
  932. Xdocumentation for any purpose and without fee is hereby granted, provided
  933. Xthat the above copyright notice appear in all copies and that both that
  934. Xcopyright notice and this permission notice appear in supporting
  935. Xdocumentation.  This software is provided "as is" without express or
  936. Ximplied warranty.
  937. SHAR_EOF
  938. if test 960 -ne "`wc -c < 'pbmtoicon.man'`"
  939. then
  940.     echo shar: error transmitting "'pbmtoicon.man'" '(should have been 960 characters)'
  941. fi
  942. fi # end of overwriting check
  943. echo shar: extracting "'pbmtops.c'" '(3728 characters)'
  944. if test -f 'pbmtops.c'
  945. then
  946.     echo shar: will not over-write existing file "'pbmtops.c'"
  947. else
  948. sed 's/^X//' << \SHAR_EOF > 'pbmtops.c'
  949. X/* pbmtops.c - read a portable bitmap and produce a PostScript bitmap file
  950. X**
  951. X** Copyright (C) 1988 by Jef Poskanzer.
  952. X**
  953. X** Permission to use, copy, modify, and distribute this software and its
  954. X** documentation for any purpose and without fee is hereby granted, provided
  955. X** that the above copyright notice appear in all copies and that both that
  956. X** copyright notice and this permission notice appear in supporting
  957. X** documentation.  This software is provided "as is" without express or
  958. X** implied warranty.
  959. X*/
  960. X
  961. X#include <stdio.h>
  962. X#ifdef    OS_SYSV
  963. X#include <string.h>
  964. X#else    OS_SYSV
  965. X#include <strings.h>
  966. X#endif    OS_SYSV
  967. X#include "pbm.h"
  968. X
  969. Xmain( argc, argv )
  970. Xint argc;
  971. Xchar *argv[];
  972. X    {
  973. X    FILE *ifd;
  974. X    bit **bits;
  975. X    int argn, rows, cols, rucols, padright, row, col;
  976. X    char ch;
  977. X    float scale;
  978. X    char name[100], *cp;
  979. X    char *usage = "usage:  %s [-s scale] [pbmfile]\n";
  980. X
  981. X    argn = 1;
  982. X    scale = 1.0;
  983. X
  984. X    /* Check for flags. */
  985. X    if ( argc > argn )
  986. X    {
  987. X    if ( argv[argn][0] == '-' )
  988. X        {
  989. X        if ( strcmp( argv[argn], "-s" ) == 0 )
  990. X        {
  991. X        if ( argc == argn + 1 )
  992. X            {
  993. X            fprintf( stderr, usage, argv[0] );
  994. X            exit( 1 );
  995. X            }
  996. X        if ( sscanf( argv[argn+1], "%f", &scale ) != 1 )
  997. X            {
  998. X            fprintf( stderr, usage, argv[0] );
  999. X            exit( 1 );
  1000. X            }
  1001. X        argn += 2;
  1002. X        }
  1003. X        else
  1004. X        {
  1005. X        fprintf( stderr, usage, argv[0] );
  1006. X        exit( 1 );
  1007. X        }
  1008. X        }
  1009. X    }
  1010. X
  1011. X    if ( argc > argn + 1 )
  1012. X    {
  1013. X    fprintf( stderr, usage, argv[0] );
  1014. X    exit( 1 );
  1015. X    }
  1016. X
  1017. X    if ( argc == argn + 1 )
  1018. X    {
  1019. X        ifd = fopen( argv[argn], "r" );
  1020. X        if ( ifd == NULL )
  1021. X        {
  1022. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  1023. X        exit( 1 );
  1024. X        }
  1025. X    strcpy( name, argv[argn] );
  1026. X
  1027. X#ifdef    OS_SYSV
  1028. X    if ( ( cp = strchr( name, '.' ) ) != 0 )
  1029. X#else    OS_SYSV
  1030. X    if ( ( cp = index( name, '.' ) ) != 0 )
  1031. X#endif    OS_SYSV
  1032. X        *cp = '\0';
  1033. X    }
  1034. X    else
  1035. X    {
  1036. X    ifd = stdin;
  1037. X    strcpy( name, "noname" );
  1038. X    }
  1039. X
  1040. X    bits = pbm_readpbm( ifd, &cols, &rows );
  1041. X
  1042. X    if ( ifd != stdin )
  1043. X    fclose( ifd );
  1044. X    
  1045. X    /* Round cols up to the nearest multiple of 8. */
  1046. X    rucols = ( cols + 7 ) / 8;
  1047. X    rucols = rucols * 8;
  1048. X    padright = rucols - cols;
  1049. X
  1050. X    putinit( name, cols, rows, scale );
  1051. X    for ( row = 0; row < rows; row++ )
  1052. X    {
  1053. X        for ( col = 0; col < cols; col++ )
  1054. X        putbit( bits[row][col] );
  1055. X    for ( col = 0; col < padright; col++ )
  1056. X        putbit( 0 );
  1057. X        }
  1058. X    putrest( );
  1059. X
  1060. X    exit( 0 );
  1061. X    }
  1062. X
  1063. X
  1064. Xint item, bitsperitem, bitshift, itemsperline, firstitem;
  1065. X
  1066. Xputinit( name, cols, rows, scale )
  1067. Xchar *name;
  1068. Xint cols, rows;
  1069. Xfloat scale;
  1070. X    {
  1071. X    int scols, srows;
  1072. X
  1073. X    scols = cols * scale * 0.96 + 0.5;    /*   0.96 is the multiple of   */
  1074. X    srows = rows * scale * 0.96 + 0.5;    /* 72/300 that is closest to 1 */
  1075. X
  1076. X    printf( "%%! %s.ps\n", name );
  1077. X    printf(
  1078. X    "%d %d translate\t%% move to lower left corner of box\n",
  1079. X    300 - ( scols/2 ), 400 - ( srows/2 ) );
  1080. X    printf( "%d %d scale\t\t%% scale box\n", scols, srows );
  1081. X    printf( "%d %d 1\t\t%% width height bits/sample\n", cols, rows );
  1082. X    printf(
  1083. X    "[ %d 0 0 -%d 0 %d ]\t%% transformation matrix\n", cols, rows, rows );
  1084. X    printf( "{ <\n" );
  1085. X
  1086. X    itemsperline = 0;
  1087. X    item = 0;
  1088. X    bitsperitem = 0;
  1089. X    bitshift = 7;
  1090. X    firstitem = 1;
  1091. X    }
  1092. X
  1093. Xputbit( b )
  1094. Xbit b;
  1095. X    {
  1096. X    if ( bitsperitem == 8 )
  1097. X    {
  1098. X    putitem( );
  1099. X    }
  1100. X    if ( ! b )
  1101. X    item += 1 << bitshift;
  1102. X    bitsperitem++;
  1103. X    bitshift--;
  1104. X    }
  1105. X
  1106. Xputrest( )
  1107. X    {
  1108. X    if ( bitsperitem > 0 )
  1109. X    putitem( );
  1110. X    printf( "\n> }\nimage\nshowpage\n" );
  1111. X    }
  1112. X
  1113. Xputitem( )
  1114. X    {
  1115. X    if ( firstitem )
  1116. X    firstitem = 0;
  1117. X    else
  1118. X    putchar( ' ' );
  1119. X    if ( itemsperline == 20 )
  1120. X    {
  1121. X    putchar( '\n' );
  1122. X    itemsperline = 0;
  1123. X    }
  1124. X    if ( itemsperline == 0 )
  1125. X    printf( "  " );
  1126. X    itemsperline++;
  1127. X    printf( "%02x", item );
  1128. X    item = 0;
  1129. X    bitsperitem = 0;
  1130. X    bitshift = 7;
  1131. X    }
  1132. SHAR_EOF
  1133. if test 3728 -ne "`wc -c < 'pbmtops.c'`"
  1134. then
  1135.     echo shar: error transmitting "'pbmtops.c'" '(should have been 3728 characters)'
  1136. fi
  1137. fi # end of overwriting check
  1138. echo shar: extracting "'pbmtops.man'" '(1139 characters)'
  1139. if test -f 'pbmtops.man'
  1140. then
  1141.     echo shar: will not over-write existing file "'pbmtops.man'"
  1142. else
  1143. sed 's/^X//' << \SHAR_EOF > 'pbmtops.man'
  1144. X.TH pbmtops 1 "19 February 1988"
  1145. X.SH NAME
  1146. Xpbmtops - convert portable bitmaps into PostScript
  1147. X.SH SYNOPSIS
  1148. Xpbmtops [pbmfile]
  1149. X.SH DESCRIPTION
  1150. XReads a portable bitmap as input.
  1151. XProduces PostScript as output.
  1152. XNote that there is no
  1153. Xpstopbm
  1154. Xtool - this transformation is one-way, because a pstopbm tool would
  1155. Xbe a full-fledged PostScript interpreter, which is beyond the scope
  1156. Xof this package.
  1157. X.SH "SEE ALSO"
  1158. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1159. Xpbmtoicon(1), pbmtocbm(1), pbmtoptx(1), pbmtorast(1),
  1160. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1161. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1162. Xpbmpaste(1), pbmenlarge(1)
  1163. X.SH AUTHOR
  1164. XCopyright (C) 1988 by Jef Poskanzer.
  1165. X
  1166. XPermission to use, copy, modify, and distribute this software and its
  1167. Xdocumentation for any purpose and without fee is hereby granted, provided
  1168. Xthat the above copyright notice appear in all copies and that both that
  1169. Xcopyright notice and this permission notice appear in supporting
  1170. Xdocumentation.  This software is provided "as is" without express or
  1171. Ximplied warranty.
  1172. SHAR_EOF
  1173. if test 1139 -ne "`wc -c < 'pbmtops.man'`"
  1174. then
  1175.     echo shar: error transmitting "'pbmtops.man'" '(should have been 1139 characters)'
  1176. fi
  1177. fi # end of overwriting check
  1178. echo shar: extracting "'pbmtoptx.c'" '(1791 characters)'
  1179. if test -f 'pbmtoptx.c'
  1180. then
  1181.     echo shar: will not over-write existing file "'pbmtoptx.c'"
  1182. else
  1183. sed 's/^X//' << \SHAR_EOF > 'pbmtoptx.c'
  1184. X/* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
  1185. X**
  1186. X** Copyright (C) 1988 by Jef Poskanzer.
  1187. X**
  1188. X** Permission to use, copy, modify, and distribute this software and its
  1189. X** documentation for any purpose and without fee is hereby granted, provided
  1190. X** that the above copyright notice appear in all copies and that both that
  1191. X** copyright notice and this permission notice appear in supporting
  1192. X** documentation.  This software is provided "as is" without express or
  1193. X** implied warranty.
  1194. X*/
  1195. X
  1196. X#include <stdio.h>
  1197. X#ifdef    OS_SYSV
  1198. X#include <string.h>
  1199. X#else    OS_SYSV
  1200. X#include <strings.h>
  1201. X#endif    OS_SYSV
  1202. X#include "pbm.h"
  1203. X
  1204. Xmain( argc, argv )
  1205. Xint argc;
  1206. Xchar *argv[];
  1207. X    {
  1208. X    FILE *ifd;
  1209. X    bit **bits;
  1210. X    int rows, cols, row, col;
  1211. X    char *usage = "usage:  %s [pbmfile]\n";
  1212. X
  1213. X    if ( argc > 2 )
  1214. X    {
  1215. X    fprintf( stderr, usage, argv[0] );
  1216. X    exit( 1 );
  1217. X    }
  1218. X
  1219. X    if ( argc == 2 )
  1220. X    {
  1221. X        ifd = fopen( argv[1], "r" );
  1222. X        if ( ifd == NULL )
  1223. X        {
  1224. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1225. X        exit( 1 );
  1226. X        }
  1227. X    }
  1228. X    else
  1229. X    ifd = stdin;
  1230. X
  1231. X    bits = pbm_readpbm( ifd, &cols, &rows );
  1232. X
  1233. X    if ( ifd != stdin )
  1234. X    fclose( ifd );
  1235. X    
  1236. X    putinit( );
  1237. X    for ( row = 0; row < rows; row++ )
  1238. X    {
  1239. X    putchar( 5 );
  1240. X        for ( col = 0; col < cols; col++ )
  1241. X        putbit( bits[row][col] );
  1242. X    putrest( );
  1243. X    putchar( '\n' );
  1244. X        }
  1245. X
  1246. X    exit( 0 );
  1247. X    }
  1248. X
  1249. X
  1250. Xchar item;
  1251. Xint bitsperitem, bitshift;
  1252. X
  1253. Xputinit( )
  1254. X    {
  1255. X    bitsperitem = 0;
  1256. X    item = 64;
  1257. X    bitshift = 0;
  1258. X    }
  1259. X
  1260. Xputbit( b )
  1261. Xbit b;
  1262. X    {
  1263. X    if ( bitsperitem == 6 )
  1264. X    putitem( );
  1265. X    if ( b )
  1266. X    item += 1 << bitshift;
  1267. X    bitsperitem++;
  1268. X    bitshift++;
  1269. X    }
  1270. X
  1271. Xputrest( )
  1272. X    {
  1273. X    if ( bitsperitem > 0 )
  1274. X    putitem( );
  1275. X    }
  1276. X
  1277. Xputitem( )
  1278. X    {
  1279. X    putchar( item );
  1280. X    bitsperitem = 0;
  1281. X    item = 64;
  1282. X    bitshift = 0;
  1283. X    }
  1284. SHAR_EOF
  1285. if test 1791 -ne "`wc -c < 'pbmtoptx.c'`"
  1286. then
  1287.     echo shar: error transmitting "'pbmtoptx.c'" '(should have been 1791 characters)'
  1288. fi
  1289. fi # end of overwriting check
  1290. echo shar: extracting "'pbmtoptx.man'" '(1072 characters)'
  1291. if test -f 'pbmtoptx.man'
  1292. then
  1293.     echo shar: will not over-write existing file "'pbmtoptx.man'"
  1294. else
  1295. sed 's/^X//' << \SHAR_EOF > 'pbmtoptx.man'
  1296. X.TH pbmtoptx 1 "13 February 1988"
  1297. X.SH NAME
  1298. Xpbmtoptx - convert portable bitmaps into Printronix printer graphics
  1299. X.SH SYNOPSIS
  1300. Xpbmtoptx [pbmfile]
  1301. X.SH DESCRIPTION
  1302. XReads a portable bitmap as input.
  1303. XProduces a file of Printronix printer graphics as output.
  1304. XNote that there is no
  1305. Xptxtopbm
  1306. Xtool - this transformation is one way.
  1307. X.SH "SEE ALSO"
  1308. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1309. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtorast(1),
  1310. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1311. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1312. Xpbmpaste(1), pbmenlarge(1)
  1313. X.SH AUTHOR
  1314. XCopyright (C) 1988 by Jef Poskanzer.
  1315. X
  1316. XPermission to use, copy, modify, and distribute this software and its
  1317. Xdocumentation for any purpose and without fee is hereby granted, provided
  1318. Xthat the above copyright notice appear in all copies and that both that
  1319. Xcopyright notice and this permission notice appear in supporting
  1320. Xdocumentation.  This software is provided "as is" without express or
  1321. Ximplied warranty.
  1322. SHAR_EOF
  1323. if test 1072 -ne "`wc -c < 'pbmtoptx.man'`"
  1324. then
  1325.     echo shar: error transmitting "'pbmtoptx.man'" '(should have been 1072 characters)'
  1326. fi
  1327. fi # end of overwriting check
  1328. echo shar: extracting "'pbmtorast.c'" '(1845 characters)'
  1329. if test -f 'pbmtorast.c'
  1330. then
  1331.     echo shar: will not over-write existing file "'pbmtorast.c'"
  1332. else
  1333. sed 's/^X//' << \SHAR_EOF > 'pbmtorast.c'
  1334. X/* pbmtorast.c - read a portable bitmap and produce a Sun rasterfile
  1335. X**
  1336. X** Copyright (C) 1988 by Jef Poskanzer.
  1337. X**
  1338. X** Permission to use, copy, modify, and distribute this software and its
  1339. X** documentation for any purpose and without fee is hereby granted, provided
  1340. X** that the above copyright notice appear in all copies and that both that
  1341. X** copyright notice and this permission notice appear in supporting
  1342. X** documentation.  This software is provided "as is" without express or
  1343. X** implied warranty.
  1344. X*/
  1345. X
  1346. X#include <stdio.h>
  1347. X#include "pbm.h"
  1348. X
  1349. X/* Because of the following include, this program compiles only on Suns. */
  1350. X#include <pixrect/pixrect_hs.h>
  1351. X
  1352. Xmain( argc, argv )
  1353. Xint argc;
  1354. Xchar *argv[];
  1355. X    {
  1356. X    FILE *ifd;
  1357. X    bit **bits;
  1358. X    int linebytes;
  1359. X    int rows, cols, row, col;
  1360. X    struct pixrect *pr;
  1361. X    short *data;
  1362. X    int shortcount, bitcount;
  1363. X
  1364. X    if ( argc > 2 )
  1365. X    {
  1366. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  1367. X    exit( 1 );
  1368. X    }
  1369. X
  1370. X    if ( argc == 2 )
  1371. X    {
  1372. X    ifd = fopen( argv[1], "r" );
  1373. X    if ( ifd == NULL )
  1374. X        {
  1375. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1376. X        exit( 1 );
  1377. X        }
  1378. X    }
  1379. X    else
  1380. X    ifd = stdin;
  1381. X
  1382. X    bits = pbm_readpbm( ifd, &cols, &rows );
  1383. X
  1384. X    if ( ifd != stdin )
  1385. X    fclose( ifd );
  1386. X    
  1387. X    if ( (pr = mem_create(cols, rows, 1)) == NULL )
  1388. X    {
  1389. X    fprintf( stderr, "Unable to create new pixrect.\n");
  1390. X    exit( 1 );
  1391. X    }
  1392. X
  1393. X    data = ((struct mpr_data *)pr->pr_data)->md_image;
  1394. X    linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
  1395. X
  1396. X    for ( row = 0; row < rows; row++ )
  1397. X    {
  1398. X    bitcount = 15;
  1399. X    shortcount = 0;
  1400. X    for ( col = 0; col < cols; col++ )
  1401. X        {
  1402. X        *(data + shortcount) |= (bits[row][col] << bitcount);
  1403. X        bitcount--;
  1404. X        if ( bitcount < 0 )
  1405. X        {
  1406. X        bitcount = 15;
  1407. X        shortcount++;
  1408. X        }
  1409. X        }
  1410. X    data += linebytes / sizeof(short);
  1411. X    }
  1412. X
  1413. X    pr_dump( pr, stdout, NULL, RT_STANDARD, 0 );
  1414. X
  1415. X    exit( 0 );
  1416. X    }
  1417. SHAR_EOF
  1418. if test 1845 -ne "`wc -c < 'pbmtorast.c'`"
  1419. then
  1420.     echo shar: error transmitting "'pbmtorast.c'" '(should have been 1845 characters)'
  1421. fi
  1422. fi # end of overwriting check
  1423. echo shar: extracting "'pbmtorast.man'" '(1068 characters)'
  1424. if test -f 'pbmtorast.man'
  1425. then
  1426.     echo shar: will not over-write existing file "'pbmtorast.man'"
  1427. else
  1428. sed 's/^X//' << \SHAR_EOF > 'pbmtorast.man'
  1429. X.TH pbmtorast 1 "18 February 1988"
  1430. X.SH NAME
  1431. Xpbmtorast - convert portable bitmaps into Sun rasters
  1432. X.SH SYNOPSIS
  1433. Xpbmtorast [pbmfile]
  1434. X.SH DESCRIPTION
  1435. XReads a portable bitmap as input.
  1436. XProduces a Sun raster file as output.
  1437. XNOTE: since it uses Sun-specific include files, pbmtorast will compile
  1438. Xonly on Suns.
  1439. X.SH "SEE ALSO"
  1440. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1441. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1),
  1442. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1443. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1444. Xpbmpaste(1), pbmenlarge(1)
  1445. X.SH AUTHOR
  1446. XBarry Klawans
  1447. X
  1448. XCopyright (C) 1988 by Jef Poskanzer.
  1449. X
  1450. XPermission to use, copy, modify, and distribute this software and its
  1451. Xdocumentation for any purpose and without fee is hereby granted, provided
  1452. Xthat the above copyright notice appear in all copies and that both that
  1453. Xcopyright notice and this permission notice appear in supporting
  1454. Xdocumentation.  This software is provided "as is" without express or
  1455. Ximplied warranty.
  1456. SHAR_EOF
  1457. if test 1068 -ne "`wc -c < 'pbmtorast.man'`"
  1458. then
  1459.     echo shar: error transmitting "'pbmtorast.man'" '(should have been 1068 characters)'
  1460. fi
  1461. fi # end of overwriting check
  1462. #    End of shell archive
  1463. exit 0
  1464.